﻿Imports ReglasNegocio

Partial Public Class Reporte_Consolidado
    Inherits System.Web.UI.Page

    Private Sub Reporte_Consolidado_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        CargaCboLocal()
        CargaFecha()
    End Sub

    '********************************
    'CARGAS INICIALES
    '*******************************

    Protected Sub CargaFecha()
        TxtFecha.Text = Now()
        'TxtFecha.Text = DateSerial(Year(Now), 1, 1)
        UPFecha.Update()
    End Sub

    Protected Sub CargaCboLocal()
        Dim i As Integer
        Dim ds As DataSet
        Dim item As ListItem
        Dim Catalogo As Combos = New Combos()
        ds = Catalogo.CboLocal()
        CboLocal.Items.Clear()
        item = New ListItem("-Todos-", "")
        CboLocal.Items.Add(item)
        For i = 0 To ds.Tables(0).Rows.Count - 1
            item = New ListItem(ds.Tables(0).Rows(i).Item(1), ds.Tables(0).Rows(i).Item(0))
            CboLocal.Items.Add(item)
        Next
        If Session.Item("Rol") = "005" Then 'CAJERO
            CboLocal.Enabled = False
            CboLocal.SelectedValue = Session.Item("LocalID")
        End If

    End Sub


    '*****************************
    '           BOTONES
    '*****************************

    Private Sub ImgBuscar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImgBuscar.Click
        CargaConsolidado(CboLocal.SelectedValue, TxtFecha.Text)
        CargaDetalleConsolidado(CboLocal.SelectedValue, TxtFecha.Text)
    End Sub
    Private Sub CargaConsolidado(ByVal pstrLocal As String, ByVal pstrFecha As String)
        Dim Catalogo As CatalogoConsolidado = New CatalogoConsolidado()
        Dim dsBandeja As DataSet
        dsBandeja = Catalogo.BandejaDetalleConsolidado(pstrLocal, pstrFecha)
        GridReporteVentas.DataSource = dsBandeja
        GridReporteVentas.DataBind()
        UPGridReporteVentas.Update()
    End Sub

    Private Sub GridReporteVentas_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridReporteVentas.PageIndexChanging
        Dim row As GridViewRow = GridReporteVentas.SelectedRow
        GridReporteVentas.PageIndex = e.NewPageIndex
        CargaConsolidado(CboLocal.SelectedValue, TxtFecha.Text)
    End Sub

    Private Sub ImgLimpiar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImgLimpiar.Click
        LimpiarFiltros()
    End Sub
    Private Sub LimpiarFiltros()
        'CboLocal.SelectedValue = ""
        TxtFecha.Text = Now()
        'UPCboLocal.Update()
        GridReporteVentas.DataSource = Nothing
        GridReporteVentas.DataBind()
        UPGridReporteVentas.Update()
    End Sub

    Private Sub CargaDetalleConsolidado(ByVal pstrLocal As String, ByVal pstrFecha As String)
        Dim Catalogo As CatalogoConsolidado = New CatalogoConsolidado()
        Dim dsBandeja As DataSet
        dsBandeja = Catalogo.AdicionalesDetalleConsolidado(pstrLocal, pstrFecha)
        LblPollos.Text = dsBandeja.Tables(0).Rows(0)("TotalPollos")
        LblEfectivo.Text = dsBandeja.Tables(0).Rows(0)("Efectivo")
        LblGastos.Text = dsBandeja.Tables(0).Rows(0)("Gastos")
        LblNeto.Text = dsBandeja.Tables(0).Rows(0)("Efectivo") - dsBandeja.Tables(0).Rows(0)("Gastos")
        panelDetalles.Visible = True
        UPDetallesConsolidado.Update()

    End Sub

    '*****************************************
    '             EXCEL BANDEJA DE EMPLEADOS
    '*****************************************
    Private Sub ImgExcel_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImgExcel.Click
        Server.Transfer("Excel/Reporte_Consolidado_Excel.aspx")
    End Sub


    'EXPONGO VARIABLES PARA EL EXCEL

    Public ReadOnly Property CodLocalExcel() As String
        Get
            Return CboLocal.SelectedValue
        End Get
    End Property

    Public ReadOnly Property NomLocalExcel() As String
        Get
            Return CboLocal.SelectedItem.Text
        End Get
    End Property

    Public ReadOnly Property FechaExcel() As String
        Get
            Return TxtFecha.Text
        End Get
    End Property


End Class